/* 
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.appspot.dispotrains.station;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class Line implements Serializable {
  public final String type;
  public final String number;
  public final int id;
  private HashSet<Station> stations = new HashSet<Station>();

  public Line(int id, String type, String number) {
    this.id = id;
    this.type = type;
    this.number = number;
  }

  public void registerStation(Station station) {
    this.stations.add(station);
  }

  public Set<Station> getStations() {
    return this.stations;
  }

  @Override
  public int hashCode() {
    return id;
  }

  @Override
  public boolean equals(Object other) {
    if (!Line.class.isInstance(other)) {
      return false;
    }
    Line otherLine = (Line) other;
    return this.id == otherLine.id;
  }

  @Override
  public String toString() {
    return this.type + " " + this.number.toUpperCase();
  }
}
